package com.example.coupon.controller;

import com.example.coupon.custom.result.R;
import com.example.coupon.entity.SysUser;
import com.example.coupon.service.SysUserService;
import com.example.coupon.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: WanChaoChao
 * @Date: 2022/6/20 15:56:21
 * @Description:
 */
@RestController
@RequestMapping(value = "/sys")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @PostMapping(path = "/login")
    public R login(@RequestBody SysUser sysUser) {
        SysUser loginUser = sysUserService.login(sysUser);
        if(null != loginUser) {
            String token = JwtUtil.generateToken(loginUser);
            return R.ok().put("token", token);
        }
        return R.error("用户名或密码错误！");
    }

    @PostMapping("/index")
    @ResponseBody
    public String index (){
        return ("ddddd");

    }



}
